﻿using Microsoft.EntityFrameworkCore;
using PHMEE.Entities.DaqInfo.TdDevices;
using PHMEE.EntityFrameworkCore;
using PHMEE.IRepositories.DaqInfo.TdDevices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace PHMEE.Repositories.DaqInfo.TdDevices
{
    /// <summary>
    /// 子表仓储
    /// </summary>
    public class TdDeviceInstanceRepository : EfCoreRepository<PHMEEDbContext, TdDeviceInstance, Guid>, ITdDeviceInstanceRepository
    {
        public TdDeviceInstanceRepository(IDbContextProvider<PHMEEDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
        /// <summary>
        /// 根据超级表ID获取子表
        /// </summary>
        /// <param name="superTableId"></param>
        /// <returns></returns>

        public async Task<List<TdDeviceInstance>> GetAttributesBySuperTableIdAsync(Guid superTableId)
        {
            var dbContext = await GetDbContextAsync();
            return await dbContext.TdDeviceInstances
                .Where(st => st.TdDeviceTypeId == superTableId)
                .OrderBy(st => st.InstanceName)
                .ToListAsync();
        }
        /// <summary>
        /// 根据id集合查询子表
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public async Task<List<TdDeviceInstance>> GetAttributesByIdAsync(List<Guid> ids)
        {
            var dbContext = await GetDbContextAsync();

            return await dbContext.TdDeviceInstances
                .Where(instance => ids.Contains(instance.Id))
                .OrderBy(instance => instance.InstanceName)
                .ToListAsync();
        }
    }
}
